home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / src / mail / smail-3.2.tar.gz / smail-3.2.tar / smail-3.2 / samples / bsmtp / batchsmtp.sh next >
Linux/UNIX/POSIX Shell Script  |  1992-09-06  |  1KB  |  61 lines

  1. #!/bin/sh
  2. # @(#) batchsmtp.sh,v 1.6 1992/09/06 04:37:45 tron Exp
  3.  
  4. # deliver messages accumlated into subdirectories of the
  5. # outq spool directory.  Subdirectory names are based on
  6. # the actual hostnames involved:
  7.  
  8. LOCALHOST=veritas.veritas.com
  9. MAXSIZE=100000
  10.  
  11. OUTQ=/usr/spool/smail/outq
  12. UUX=/usr/bin/uux
  13.  
  14. cd $OUTQ || exit 1
  15.  
  16. # loop through all of the subdirectories
  17. for host in *
  18. do
  19.     (
  20.     # change to directory or exit subshell
  21.     test -d $host || exit
  22.     cd $host || exit 1
  23.  
  24.     # send multiple batches
  25.     while :
  26.     do
  27.         # get the list of message files; quit if none
  28.         msgs="`ls 2>/dev/null | grep '^q'`"
  29.         test -n "$msgs" || break
  30.  
  31.         # accumulate until total size exceeds maximum
  32.         send=
  33.         sz=0
  34.         for f in $msgs
  35.         do
  36.             send="$send $f"
  37.             n=`wc -c <$f 2>/dev/null`
  38.             test -n "$n" || continue
  39.             sz=`expr $sz + $n`
  40.             test $sz -lt $MAXSIZE || break
  41.         done
  42.  
  43.         # send messages, adding HELO and QUIT commands
  44.         ( echo "HELO $LOCALHOST"
  45.           for f in $send
  46.           do
  47.               cat $f
  48.           done
  49.           echo QUIT ) | $UUX - $host!rsmtp
  50.  
  51.         # remove messages that were sent
  52.         for f in $send
  53.         do
  54.             rm $f
  55.         done
  56.     done
  57.     )
  58. done
  59.  
  60. exit 0
  61.